package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "select t.id,t.name,t.salary,t.title,c.name " +
                    "from teacher t " +
                    "join class c on c.teacher_id=t.id";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()){
                int id = rs.getInt("t.id");
                String name = rs.getString("t.name");
                String cName = rs.getString("c.name");
                int salary = rs.getInt("t.salary");
                String title = rs.getString("t.title");
                System.out.println(id+" "+name+" "+salary+" "+title+" "+cName);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
